#include <vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    int minPathSum(vector<vector<int>>& grid) {
        vector<vector<int>>dp(grid);
        for(int i=0;i<dp.size();i++){
            for(int j=0;j<dp[i].size();j++){
                if(!i&&!j)continue;
                int up=i-1>=0?dp[i-1][j]:INT_MAX;
                int left=j-1>=0?dp[i][j-1]:INT_MAX;
                dp[i][j]+=min(up,left);
            }
        }
        return dp.back().back();
    }
};